package restdom.validation.impl;

import org.springframework.validation.BindException;
import org.springframework.validation.Errors;
import org.springframework.validation.Validator;

import restdom.validation.ValidationSupport;


/**
 * 
 * @deprecated
 */
@Deprecated
public class DefaultValidationSupport implements ValidationSupport {

	private Validator validator;

	private Validator onCreateValidator;

	private Validator onUpdateValidator;

	public Errors validate(Object instance) {
		BindException errors = new BindException(instance, "instance");

		if (validator != null) {
			validator.validate(instance, errors);
		}

		return errors;
	}

	public Errors validateOnCreate(Object instance) {
		Errors errors = validate(instance);

		if (onCreateValidator != null && !errors.hasErrors()) {
			onCreateValidator.validate(instance, errors);
		}

		return errors;
	}

	public Errors validateOnUpdate(Object instance) {
		Errors errors = validate(instance);

		if (onUpdateValidator != null && !errors.hasErrors()) {
			onUpdateValidator.validate(instance, errors);
		}

		return errors;
	}

	public Validator getValidator() {
		return validator;
	}

	public void setValidator(Validator validator) {
		this.validator = validator;
	}

	public void setOnCreateValidator(Validator validator) {
		onCreateValidator = validator;
	}

	public void setOnUpdateValidator(Validator validator) {
		onUpdateValidator = validator;
	}

}
